package com.yztstudy.Utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

/**
 * 文件函数工具类
 */

public class FileFunctionUtils {

    /**
     *  复制文件。如果目标文件存在，会被覆盖。
     * @param srcFile 源文件
     * @param destFile 目标文件
     * @throws IOException
     */
    public static void copyFile(File srcFile, File destFile)
            throws IOException {
        FileInputStream inStream = new FileInputStream(srcFile);
        FileOutputStream outStream = new FileOutputStream(destFile);
        FileChannel inChannel = inStream.getChannel();
        FileChannel outChannel = outStream.getChannel();
        inChannel.transferTo(0, inChannel.size(), outChannel);
        inStream.close();
        inChannel.close();
        outStream.close();
        outChannel.close();
    }
}
